<?php

/*

Inbox (mail.php)

*/

$page_title = "Instant Messanger";
$rank_check = 3;
include "header.inc.php";

ECHO <<<END

<HTML>
<HEAD>
   <TITLE>$gameName2 - $page_title</TITLE>
	<style><!--
    INPUT {color:#000000; font: 9pt verdana; font-weight: none; text-decoration: none; 	background: #$maincellColor; border: 1 solid #$topAndBottomBG; }
	TEXTAREA {color:#000000; font: 9pt verdana; font-weight: none; text-decoration: none; 	background: #$maincellColor; border: 1 solid #$topAndBottomBG; }
	BUTTON {color:#000000; font: 9pt verdana; font-weight: none; text-decoration: none; 	background: #$maincellColor; border: 0 solid #$topAndBottomBG; }
	SELECT {color:#000000; font: 9pt verdana; font-weight: none; text-decoration: none; 	background: #$maincellColor; border: 1 solid #$topAndBottomBG; }
	INPUT {color:#000000; font: 9pt verdana; font-weight: none; text-decoration: none; 	background: #$maincellColor; border: 1 solid #$topAndBottomBG; }
	OPTION {color:#000000; font: 9pt verdana; font-weight: none; text-decoration: none; 	background: #$maincellColor; border: 1 solid #$topAndBottomBG; }
	RESET {color:#000000; font: 9pt verdana; font-weight: none; text-decoration: none; 	background: #$maincellColor; border: 1 solid #$topAndBottomBG; }
	SUBMIT {color:#000000; font: 9pt verdana; font-weight: none; text-decoration: none; 	background: #$maincellColor; border: 1 solid #$topAndBottomBG; }
	A:link {
	text-decoration:  underline;
	color: #$mainlinkColor;
	}
	A:visited {
	text-decoration:  underline;
	color: #$mainlinkColor;
	}
	A:hover {
	text-decoration:  underline;
	color: #$mainlinkColor;
	}
	A:active {
	text-decoration:  underline;
	color: #$mainlinkColor;
	}
	A:link.menu {
	text-decoration:  underline;
	color: #$menulinkColor;
	}
	A:visited.menu {
	text-decoration:  underline;
	color: #$menulinkColor;
	}
	A:hover.menu {
	text-decoration:  underline;
	color: #$menulinkColor;
	}
	A:active.menu {
	text-decoration:  underline;
	color: #$menulinkColor;
	}
	A:link.bottom {
	text-decoration:  underline;
	color: #$bottomlinkColor;
	}
	A:visited.bottom {
	text-decoration:  underline;
	color: #$bottomlinkColor;
	}
	A:hover.bottom {
	text-decoration:  underline;
	color: #$bottomlinkColor;
	}
	A:active.bottom {
	text-decoration:  underline;
	color: #$bottomlinkColor;
	}
	p
	{
	font-family: verdana;
	font-size: 11pt;
	color: black;
	}
	p.error
	{
	font-family: verdana;
	font-weight: bold;
	color: red;
	}
	p.white
	{
	font-family: verdana;
	color: white;
	}
	a.white
	{
	color: white;
	text-decoration: underline;
	}
	hr
	{
	margin: -1;
	}
	img
	{
	border: 0
	}
	--></style>

</HEAD>
<BODY BGCOLOR="#$backgroundColor">

END;



if ($page == "knock")
{
	$findMsg = fetch("SELECT * FROM instant_msg WHERE send_to = '$userid' AND game = '$game' AND id = '$id'");
	if (!$findMsg[id])
	{
		print "<center><font size=+2>This instant message does not exsist.</font></center>";
		$page = "blah";
	}

	print "<center>Instant Message from $findMsg[sender]<br><br><table><tr><td>
<form action=instant_messenger.php?game=$game&read=true&id=$findMsg[id] method=post>
<input type=submit value=\"Accept\">
</form></td><td>
<form action=instant_messenger.php?game=$game&read=false&id=$findMsg[id] method=post>
<input type=submit value=\"Decline\">
</form></td></tr></table></center>";
}

if ($page == "send")
{
	$buddyCheck = fetch("SELECT id FROM buds2 WHERE bud_me = '$userid' AND bud_you = '$members[id]' AND game = '$game'");
	if (!$buddyCheck[id])
	{
		die("Sorry you must be this user's buddy to send them instant messages.</body></html>");
	}
	$onlineCheck = fetch("SELECT id FROM members2 WHERE username = '$send_to' AND last_hit >= '$onlineTimeLimit' AND game = '$game'");
	if (!$onlineCheck[id])
	{
		die("Sorry this user must be online for you to send them instant messages. Try sending them a <a href=mail.php?game=$game>mail</a> instead.</body></html>");
	}
	print "<p>Send to: $send_to<br>
	<TEXTAREA NAME=message ROWS=7 COLS=45 WRAP=virtual></TEXTAREA><br>
	<input type=submit value=\"Send Instant Message\">";
}

print "</BODY></HTML>";

?>